#ifndef AUDIOFILE_H
#define AUDIOFILE_H

#include <qstring.h>
#include <qset.h>
#include <qfileinfo.h>
#include <qicon.h>

class PlaylistEntry;
struct id3_tag;

class AudioFile : public QObject
{
    Q_OBJECT
    Q_DISABLE_COPY(AudioFile)

public:
    AudioFile(const QString& i_filepath);
    virtual ~AudioFile();

    inline const QFileInfo& fileInfo() const {return m_fileInfo;}
    inline const QString& filename() const {return m_filename;}
    inline int entriesCount() const {return m_playlistEntries.size();}
    inline const QSet<PlaylistEntry*>& entries() const {return m_playlistEntries;}
    inline const QString& tags() const {return m_tagString;}
    inline bool hasCover() const {return m_hasCover;}
    inline bool hasLyrics() const {return m_hasLyrics;}
    inline const QIcon& cover() const {return m_cover;}
    inline const QString& artist() const {return m_artist;}
    inline const QString& title() const {return m_title;}
    inline const QString& album() const {return m_album;}
    inline const QString& genre() const {return m_genre;}
    inline const QString& track() const {return m_track;}
    inline const QString& year() const {return m_year;}

    void addPlaylistEntry(PlaylistEntry* i_pEntry);
    void removePlaylistEntry(PlaylistEntry* i_pEntry);
    void readTags(bool i_refresh = false);

signals:
    void dataChanged();

private:
    static QString getTagTextField(id3_tag* i_pTag, const char* i_frame);
    static bool hasTagUnsyncedLyrics(id3_tag* i_pTag);
    static bool hasTagSyncedLyrics(id3_tag* i_pTag);

private:
    const QFileInfo m_fileInfo;
    const QString m_filename;
    QSet<PlaylistEntry*> m_playlistEntries;

    bool m_tagsRead;
    bool m_hasLyrics;
    bool m_hasCover;
    QString m_tagString;
    QIcon m_cover;
    QString m_artist;
    QString m_title;
    QString m_album;
    QString m_genre;
    QString m_track;
    QString m_year;

    static QIcon DEFAULT_ICON;
};

#endif // AUDIOFILE_H
